home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / plot / subs.c < prev   
Encoding:
C/C++ Source or Header  |  1989-04-03  |  4.0 KB  |  182 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: subs.c,v 4.1 88/06/21 14:03:15 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/plot/RCS/subs.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/plot/RCS/subs.c,v $$Revision: 4.1 $";
  12.  
  13.  
  14. /* mgr plot filter (tmgr) */
  15.  
  16. #include "term.h"
  17. #define Yf(y) (ymax - (y))    /* flip vertically (khera@cs.duke.edu) */
  18. #define Y(x)  (scale?(int)((Yf(x)-ymin) * yscale):Yf(x))
  19. #define X(x)    (scale?(int)(((x)-xmin) * xscale):(x))
  20. #define dprintf    if(debug)fprintf
  21. #define GMAX     999
  22.  
  23. static int scale = 0;            /* TRUE if scaling on */
  24. static int xmin = 0 ,ymin = 0;        /* minimum plotting coord */
  25. static int xmax = GMAX ,ymax = GMAX;    /* maximum plotting coord */
  26. static int xgmax = GMAX;        /* to override GMAX from environ() */
  27. static int ygmax = GMAX;
  28. static float xscale,yscale;        /* scale values */
  29. static int debug = 0;            /* iff TRUE debug -> stderr */
  30. static int text;            /* true if last item was a label */
  31. static int win_id = 0;            /* true for alternate window */
  32. static int pause = 0;            /* pause before clear */
  33. static int points=0;            /* # points plotted (>0) */
  34.  
  35. openpl()
  36.    {
  37.    char *getenv();
  38.    int n;
  39.    char *v;
  40.  
  41.    if ((v=getenv("MAX_X")) && (n=atoi(v))>0)
  42.       xgmax = n;
  43.    if ((v=getenv("MAX_Y")) && (n=atoi(v))>0)
  44.       ygmax = n;
  45.    if ((v=getenv("WINDOW_ID")) && (n=atoi(v))>0)
  46.       win_id = n;
  47.    pause = (int) getenv("PAUSE");
  48.    points = 0;
  49.  
  50.    xscale = (float)xgmax/(xmax-xmin);
  51.    yscale = (float)ygmax/(ymax-ymin);
  52.    text = 0;
  53.    debug = (int)getenv("DEBUG");
  54.    dprintf(stderr,"OPEN\n");
  55.    m_setup(M_DEBUG);
  56.    m_push(P_FLAGS);
  57.    m_func(B_SET);
  58.    if (win_id) {
  59.       m_selectwin(win_id);
  60.       m_setmode(M_ACTIVATE);
  61.       }
  62.    }
  63.  
  64. erase()
  65.    {
  66.    if (points && pause) {
  67.       m_flush();
  68.       getpass("\0330,0M");
  69.       }
  70.    m_clear();
  71.    m_flush();
  72.    dprintf(stderr,"ERASE\n");
  73.    points = 0;
  74.    }
  75.  
  76. label(s)
  77. char *s;
  78.    {
  79.    if (text == 0)
  80.       m_aligntext();
  81.    m_setmode(M_OVERSTRIKE);
  82.    m_func(B_OR);
  83.    m_printstr(s);
  84.    m_func(B_SET);
  85.    m_clearmode(M_OVERSTRIKE);
  86.    dprintf(stderr,"LABEL [%s]\n",s);
  87.    text++;
  88.    points++;
  89.    }
  90.  
  91. line(x1, y1, x2, y2)
  92. int x1,y1,x2,y2;
  93.    {
  94.    text=0;
  95.    m_line(X(x1),Y(y1),X(x2),Y(y2));
  96.    m_go(X(x2),Y(y2));        /* this should be redundant */
  97.    dprintf(stderr,"LINE: %d,%d  %d,%d\n",X(x1),Y(y1),X(x2),Y(y2));
  98.    points++;
  99.    }
  100.  
  101. circle(x, y, r)
  102. int x,y,r;
  103.    {
  104.    m_circle(X(x),Y(y),X(r));
  105.    dprintf(stderr,"CIRCLE %d,%d  %d\n",X(x),Y(y),X(r));
  106.    points++;
  107.    }
  108.  
  109. arc(x, y, x0, y0, x1, y1)
  110. int x,y,x0,y0,x1,y1;
  111.    {
  112.    m_arc(X(x),Y(y),X(x0),Y(y0),X(x1),Y(y1));
  113.    dprintf(stderr,"ARC at %d,%d from  %d,%d to %d,%d\n",
  114.                 X(x),Y(y),X(x0),Y(y0),X(x1),Y(y1));
  115.    points++;
  116.    }
  117.  
  118. move(x, y)
  119. int x,y;
  120.    {
  121.    text=0;
  122.    m_go(X(x),Y(y));
  123.    dprintf(stderr,"MOVE %d,%d\n",X(x),Y(y));
  124.    }
  125.  
  126. cont(x, y)
  127. int x,y;
  128.    {
  129.    text=0;
  130.    m_draw(X(x),Y(y));
  131.    dprintf(stderr,"DRAW %d,%d\n",X(x),Y(y));
  132.    points++;
  133.    }
  134.  
  135. point(x, y)
  136. int x,y;
  137.    {
  138.    m_line(X(x),Y(y),X(x),Y(y));
  139.    dprintf(stderr,"POINT %d,%d\n",X(x),Y(y));
  140.    points++;
  141.    }
  142.  
  143. linemod(s)
  144. char *s;
  145.    {
  146.    dprintf(stderr,"LINEMODE [%s]\n",s);
  147.    }
  148.  
  149. space(x0, y0, x1, y1)
  150. int x0,y0,x1,y1;
  151.    {
  152.    xmin = x0;
  153.    ymin = y0;
  154.    xmax = x1;
  155.    ymax = y1;
  156.    xscale = (float)xgmax/(xmax-xmin);
  157.    yscale = (float)ygmax/(ymax-ymin);
  158.    scale = 1;
  159.    dprintf(stderr,"SPACE %d,%d to %d,%d: scale (%g,%g)\n",
  160.             xmin,ymin,xmax,ymax,xscale,yscale);
  161.    }
  162.  
  163. closepl()
  164.    {
  165.    if (points && pause) {
  166.       m_flush();
  167.       getpass("\0330,0M");
  168.       }
  169.    if (win_id) {
  170.       m_selectwin(0);
  171.       m_setmode(M_ACTIVATE);
  172.       }
  173.    m_pop();
  174.    m_flush();
  175.    points++;
  176.    dprintf(stderr,"CLOSE\n");
  177.    }
  178.  
  179. dot()
  180.   {
  181.   }
  182.